home *** CD-ROM | disk | FTP | other *** search
- Path: news.pge.com!usenet
- From: psk3@pge.com (Phillip Knight)
- Newsgroups: comp.lang.c++
- Subject: overiding c++ stream classes anyone?
- Date: 23 Jan 1996 01:20:47 GMT
- Organization: Pacific Gas and Electric
- Message-ID: <4e1d5f$5en@news02.comp.pge.com>
- References: <4cqbja$62n@earth.njcc.com>
- NNTP-Posting-Host: psk3ws04.comp.pge.com
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=US-ASCII
- X-Newsreader: WinVN 0.99.6
-
- I have pulled the last hair out of my head and still have not solved this
- problem:
-
- class X : public ostream {
- public:
- ...
- X& operator<<(X& (*f)(X&)) { return (*f)(*this); }
- };
-
-
- X& newl(X& os) {
- cerr << "this never gets printed" << endl;
- }
-
- main() {
- X foo;
- foo << "test one";
- foo << endl;
-
- foo << "test two" << endl;
- }
-
- so the problem is simple: how do i get my manipulator newl to be called? This
- program as stands does not compile, because inclusion of the operator '<<'
- (used in order to execute the manipulator) causes class X to no longer
- recognize the base class operators (it only recognizes X's operator <<).
- taking the operator out of the class and into the code as a function doesn't
- solve the problem either as newl never gets called.
-
- so anyone know a simple way of overloading a manipulator? (all this when all
- i really need is a virtual flush...)
-
- thanks in advance...
- phil knight
- psk3@pge.com
-
-